#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    id=startTimer(1000);//创建每1s触发一次函数的定时器id
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::timerEvent(QTimerEvent(*ev))
{
     if(ev->timerId()==id)
     {
        int value= ui->lcdNumber->value();
        if(value<=0)
        {
            killTimer(id);//删除定时器对应的id
            return ;
        }
        ui->lcdNumber->display(value-1);//改LCD的值
     }


}

